package com.sc.web.gwt.client.view.uicomponent;

/**
 * User: KienCT
 * Date: 22/07/2011
 * Time: 10:02
 */

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;

/**
 * The dialog contains only Ok button
 */
public class OkDialog extends Dialog {

    private final Label info;

    private ClickHandler okHandler;

    public OkDialog(DialogMessages messages) {
        info = new Label();

        RESOURCES.dialogCSS().ensureInjected();
        info.addStyleName(RESOURCES.dialogCSS().infoLabel());

        setBody(info);

        Button okButton = new Button(messages.ok());
        okButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                okHandler.onClick(event);
            }
        });

        addButton(okButton);
    }

    /**
     * show a confirmation dialog (Yes/No), with the given yes handlers.
     */
    public void show(String title, String infoMsg, ClickHandler yesHandler) {
        this.okHandler = yesHandler;

        setTitle(title);
        info.setText(infoMsg);

        center();
        show();
    }
}